$(function() {
	//设置活动按钮
	changeHeaderMenu(0);
	changeMenu(0, 5);
	// 初始化
	$('#deviceSn').val('');
	$('#deviceSn2').val('');
});

function sure() {
	var deviceSn = $('#deviceSn').val();
	var deviceSn2 = $('#deviceSn2').val();
	if(!deviceSn || !deviceSn2) {
		$('#alertdiv').savehandle('setmsg',{msg:'请输入设备SN！',timer:5000});
		return;
	}
	if(deviceSn != deviceSn2) {
		$('#alertdiv').savehandle('setmsg',{msg:'两次输入的设备SN不一致！',timer:5000});
		return;
	}
	add();
}

var adding = false;
function add() {
	if(adding)
		return;
	adding = true;
	var rlyModel = $('#rlyModel').val();
	var deviceModel = $('#deviceModel').val();
	var deviceSn = $('#deviceSn').val();
	var supplier = $('#supplier').val();
	var note = $('#note').val();
    data = {
		'rlyModel': rlyModel,
    	'deviceModel': deviceModel,
	    'sn': deviceSn,
	    'supplier': supplier,
	    'note': note
    };
    $.getJSON('/fw/agent/agentSro_add.action', data, function(data){
		if(data.success && data.result){
			$('#deviceSn').val('');
			$('#deviceSn2').val('');
			layer.confirm('已将该设备登记为官方设备，是否需要立即授权？', {
				btn : [ '暂不授权', '去授权' ]
			}, function() {
				layer.closeAll();
			}, function() {
				location.href = 'deviceAuz.jsp';
			});
		} else {
			$('#alertdiv').savehandle('setmsg',{msg:data.result.errors?data.result.errors:'保存失败', timer: 2000});
		}
		adding = false;
	});
}